﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Threading.Tasks;

namespace KD.Sms.DAL.SqlLite
{
    internal sealed partial class Main
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DataTable DoQueryPailsForOperate()
        {
            return SQLiteHelper.GetDataTable(@"select Pail_Name,Codes,Threshold_Value,Current_Value,Threshold_Weight,Current_Weight,case when status = 0 then '已启用' else '已禁用' end as status,'复位' as fw,'修改' as xg,case when status = 0 then '禁用' else '启用' end as sz from S_Pail");
        }

        /// <summary>
        /// 复位样桶
        /// </summary>
        /// <param name="pailid"></param>
        /// <returns></returns>
        public bool DoRestPail(string pailid)
        {
            _strSql = "update S_Pail set codes = null,Current_Value = 0,Current_Weight= 0,status = 0 ";
            if (!string.IsNullOrEmpty(pailid))
                _strSql += string.Format(" where Pail_id = {0}", pailid);
            return SQLiteHelper.ExecuteNonQuery(_strSql, null) > 0;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pailid"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool DoSetPailStatus(string pailid, bool value)
        {
            _strSql = string.Format("update S_Pail set status = {0} where Pail_id = {1}", Convert.ToInt32(!value), pailid);
            return SQLiteHelper.ExecuteNonQuery(_strSql, null) > 0;
        }

        /// <summary>
        /// 设置样桶阈值
        /// </summary>
        /// <param name="pailid"></param>
        /// <param name="value"></param>
        /// <param name="weight"></param>
        /// <returns></returns>
        public bool DoSetPailConfig(string pailid, string value, string weight)
        {
            _strSql = string.Format("update S_Pail set Threshold_Value = {0},Threshold_Weight = {1} where Pail_id = {2}", value, weight, pailid);
            return SQLiteHelper.ExecuteNonQuery(_strSql, null) > 0;
        }
    }
}
